print("About nodemcu...")
print("======================================")

print("Config AP....")
wifi.setmode(wifi.STATION)

ap_ssid="HiWiFi_SMT"
ap_pwd="87654321"
print(string.format("AP config: SSID=%s,%s",ap_ssid,ap_pwd))
wifi.sta.config(ap_ssid,ap_pwd)

waitconnect()

print("======================================")
print("CHIP ID: "..node.chipid())
print("HEAP SIZE: "..node.heap())
print("AP MAC: "..wifi.sta.getmac())
print("STA MAC: "..wifi.ap.getmac())
print("WiFi mode: "..wifi.getmode())
print("IP: "..wifi.sta.getip())
print("======================================")
print("This info come from openthings@163.com")

print("Connect AP, Waiting...") 
tCount=0
function waitconnect()
	tmr.alarm(1000, 1, function() 
		if wifi.sta.getip()=="0.0.0.0" then
			tCount=tCount+1
			print tCount,".";
			--io.output("")
			if tCount>10 then
				print("O! My god, AP unavailable.")
				print("May set wifi.setmode(wifi.STATION)")
				print("and use wifi.sta.config(ssid,pwd) to set AP.")
				tmr.stop()
			end
		else
			startServer()
			tmr.stop()
		end
	end)

end
